package com.five.util;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebFilter(filterName = "EncodeeFilter", value = "/view/backstage/*")
public class EncodeeFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        HttpSession session = request.getSession();
        Object name = session.getAttribute("name");
//        Object pwd = session.getAttribute("pwd");
//        Object imgpath = session.getAttribute("imgpath");
//        Object id = session.getAttribute("id");
//        Object roleid = session.getAttribute("roleid");
      if (name != null) {
           //过滤链放行
            filterChain.doFilter(request, response);
        }else {
            response.sendRedirect("/Hotel/view/login/login.jsp");
        }
    }
    @Override
    public void destroy() {
    }
}
